﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.WindowsAzure;
using ZeCloud.Techdays.Business;
using ZeCloud.Techdays.Model;

namespace ZeCloud.Techdays
{
    public partial class Questions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ValidateForm(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
                return;

            CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("MyStorage");

            var context = new ServiceContext(account);

            var newQuestion = new Question
                                       {
                                           FirstName = txtFirstName.Text,
                                           LastName = txtLastName.Text,
                                           Email = txtEmail.Text,
                                           Request = txtQuestion.Text
                                       };

            context.Insert(newQuestion);

            ClearBox();
            lblSuccess.Visible = true;
        }

        private void ClearBox()
        {
            txtFirstName.Text = txtLastName.Text = txtEmail.Text = txtQuestion.Text = string.Empty;
        }
    }
}